package com.njupt.yanglonglong.report.demo.utils.websocket;

/**
 * @className: BaseData
 * @Description: TODO
 * @author: lpl
 * @date: 2021/5/17 16:52
 */
public class BaseData {
    public static final int DATACLASS_LENGTH = 1472; //byte
    public static final int HEADER_LENGTH = 8;       //byte
    private byte ctrl;          //4bit
    private byte type;          //4bit
    private int length_total;   //24bit
    private short number;       //16bit
    private short length_data;  //16bit
    private byte[] data = new byte[DATACLASS_LENGTH - HEADER_LENGTH];

    public static String bytesToHexString(byte[] src) {

        StringBuilder stringBuilder = new StringBuilder("");

        if (src == null || src.length <= 0) {

            return null;

        }

        for (int i = 0; i < src.length; i++) {

            int v = src[i] & 0xFF;

            String hv = Integer.toHexString(v);

            if (hv.length() < 2) {

                stringBuilder.append(0);

            }

            stringBuilder.append(hv);

        }

        return stringBuilder.toString();

    }

    public byte getCtrl() {
        return ctrl;
    }

    public void setCtrl(byte ctrl) {
        this.ctrl = ctrl;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public int getLength_total() {
        return length_total;
    }

    public void setLength_total(int length_total) {
        this.length_total = length_total;
    }

    public short getNumber() {
        return number;
    }

    public void setNumber(short number) {
        this.number = number;
    }

    public short getLength_data() {
        return length_data;
    }

    public void setLength_data(short length_data) {
        this.length_data = length_data;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "BaseData{" +
                "ctrl=" + Integer.toHexString(ctrl) +
                ", type=" + Integer.toHexString(type) +
                ", length_total=" + Integer.toHexString(length_total) +
                ", number=" + Integer.toHexString(number) +
                ", length_data=" + Integer.toHexString(length_data) +
                ", data=" + bytesToHexString(data) +
                '}';
    }
}
